// 封装接口
export const baseURL = 'https://www.codeboy.com/zhsqapi/'
// 登录接口
export const userLogin = async (phone, pwd) => {
	const url = baseURL + 'user/login'
	//加载中提示框
	uni.showLoading({
		title: '用户登录中...',

	})
	//发送请求
	const res = await uni.request({
		url,
		method: "POST",
		data: {
			phone,
			pwd
		}
	})
	//隐藏提示框
	uni.hideLoading()
	return res.data
}
// 首页接口
export const indexData = async () => {
	const url = baseURL + 'index/data'
	uni.showLoading({
		title: '数据加载中',
	})
	const res = await uni.request({
		url,
		header: {
			token: uni.getStorageSync('userToken')
		}
	})
	uni.hideLoading()
	return res.data
}
//当前登录用户各项待缴费金额汇总
export const feeList = async () => {
	const url = baseURL + 'fee/list'
	uni.showLoading({
		title: '数据加载中',
	})
	const res = await uni.request({
		url,
		header: {
			token: uni.getStorageSync('userToken')
		}
	})
	uni.hideLoading()
	return res.data
}

//当前登录用户缴费记录
export const feeRecord = async (type, startTime, endTime) => {
	const url = baseURL + 'fee/record'
	uni.showLoading({
		title: '缴费记录加载中',
	})
	const res = await uni.request({
		url,
		header: {
			token: uni.getStorageSync('userToken')
		},
		data: {
			type,
			startTime,
			endTime
		}
	})
	uni.hideLoading()
	return res.data
}

// 获取指定类型的收费单位列表
export const feeCollector = async (type) => {
	const url = baseURL + 'fee/collector'
	uni.showLoading({
		title: '缴费单位加载中',
	})
	const res = await uni.request({
		url,
		data: {
			type
		}
	})
	uni.hideLoading()
	return res.data
}
// 根据业主缴费编号查询该业主的基本信息
export const householdQuery = async (hhid) => {
	const url = baseURL + 'fee/household/query'
	uni.showLoading({
		title: '业主信息加载中',
	})
	const res = await uni.request({
		url,
		data: {
			hhid
		}
	})
	uni.hideLoading()
	return res.data
}
//提交缴费记录
export const feeAdd = async (type, collectorId, householdId, amount) => {
	const url = baseURL + 'fee/add'
	uni.showLoading({
		title: '提交缴费中',
	})
	const res = await uni.request({
		url,
		method: "POST",
		header: {
			token: uni.getStorageSync('userToken')
		},
		data: {
			type,
			collectorId,
			householdId,
			amount
		}
	})
	uni.hideLoading()
	return res.data
}
// 返回所有停车区坐标及当前空闲数据

export const parkingZoneList = async () => {
	const url = baseURL + 'parking/zone/list'
	uni.showLoading({
		title: '停车区数据加载中',
	})
	const res = await uni.request({
		url,
	})
	uni.hideLoading()
	return res.data
}